<%@ include file="/common/taglibs.jsp"%>

<title><fmt:message key="agendaForm.title" /></title>
<content tag="heading">
<fmt:message key="agendaForm.heading" />
</content>

<spring:bind path="agenda.*">
	<c:if test="${not empty status.errorMessages}">
		<div class="error"><c:forEach var="error"
			items="${status.errorMessages}">
			<img src="<c:url value="/images/iconWarning.gif"/>"
				alt="<fmt:message key="icon.warning"/>" class="icon" />
			<c:out value="${error}" escapeXml="false" />
			<br />
		</c:forEach></div>
	</c:if>
</spring:bind>

<c:set var="buttons">
	<div id=xh style="display:none">
	<input type="submit" class="button" name="save" onclick="bCancel=false"
		value="<fmt:message key="button.save"/>" />
	<input type="submit" class="button" name="delete"
		onclick="bCancel=true;return confirmDelete('Agenda')"
		value="<fmt:message key="button.delete"/>" />
	<input type="submit" class="button" name="mail"
		onclick="bCancel=false;return confirmSendMail()"
		value="<fmt:message key="button.mail"/>" />
	<input type="button" class="button" name="check"
		onclick="bCancel=false;checkRole(agendaForm)"
		value="<fmt:message key="button.check"/>" />
	<input type="button" class="button"
		onclick="location.href='<c:url value="/agendas.html"/>'"
		value="<fmt:message key="button.cancel"/>" />
	</div>
</c:set>

<spring:htmlEscape defaultHtmlEscape="true" />
<form:form commandName="agenda" method="post" action="dwrtest.html"
	id="agendaForm" name="agendaForm">
	<ul>
		<form:hidden path="id" />
		<li>
		<div>
		<div class="left"><toastmaster:label styleClass="desc"
			key="agenda.venue" /> <form:errors path="venue"
			cssClass="fieldError" /> <form:input path="venue" id="venue"
			cssClass="text medium" /></div>
		<div><toastmaster:label styleClass="desc" key="agenda.date" />
		<form:errors path="date" cssClass="fieldError" /> <form:input
			path="date" id="date" cssClass="text medium" /></div>
		</div>
		</li>
		<li><toastmaster:label styleClass="desc" key="agenda.theme" /> <form:errors
			path="theme" cssClass="fieldError" /> <form:input path="theme"
			id="theme" cssClass="text large" /></li>
		<li><toastmaster:label styleClass="desc" key="agenda.phrase" />
		<form:errors path="phrase" cssClass="fieldError" /> <form:input
			path="phrase.phrase" id="phrase" cssClass="text large" /></li>

		<li><toastmaster:label styleClass="desc"
			key="agenda.phrase_definition" /> <form:errors path="phrase"
			cssClass="fieldError" /> <form:input path="phrase.definition"
			id="phrase" cssClass="text large" /></li>

		<li><toastmaster:label styleClass="desc"
			key="agenda.phrase_example" /> <form:errors path="phrase"
			cssClass="fieldError" /> <form:input path="phrase.example"
			id="phrase" cssClass="text large" /></li>

		<table>
			<tr>
				<td><toastmaster:label styleClass="desc" key="agenda.president" />
				<select class="medium" name="role_president" id="role_president"></select></td>
				<td><toastmaster:label styleClass="desc"
					key="agenda.toastmaster" /> <select class="medium"
					name="role_toastmaster" id="role_toastmaster"></select></td>
			</tr>
			<tr>
				<td><toastmaster:label styleClass="desc"
					key="agenda.table_topic_master" /> <select class="medium"
					name="role_table_topic_master" id="role_table_topic_master"></select></td>
				<td><toastmaster:label styleClass="desc"
					key="agenda.general_evaluator" /> <select class="medium"
					name="role_general_evaluator" id="role_general_evaluator"></select></td>
			</tr>
			<tr>
				<td>
				<div class="left"><toastmaster:label styleClass="desc"
					key="agenda.speaker1" /> <select class="medium"
					name="role_speaker1" id="role_speaker1"></select></div>
				</td>
				<td>
				<div><toastmaster:label styleClass="desc"
					key="agenda.evaluator1" /> <select class="medium"
					name="role_evaluator1" id="role_evaluator1"></select></div>
				</td>
			</tr>
			<tr>
				<td>
				<div class="left"><toastmaster:label styleClass="desc"
					key="agenda.speaker2" /> <select class="medium"
					name="role_speaker2" id="role_speaker2"></select></div>
				</td>
				<td>
				<div><toastmaster:label styleClass="desc"
					key="agenda.evaluator2" /> <select class="medium"
					name="role_evaluator2" id="role_evaluator2"></select></div>
				</td>
			</tr>
			<tr>
				<td>
				<div class="left"><toastmaster:label styleClass="desc"
					key="agenda.speaker3" /> <select class="medium"
					name="role_speaker3" id="role_speaker3"></select></div>
				</td>
				<td>
				<div><toastmaster:label styleClass="desc"
					key="agenda.evaluator3" /> <select class="medium"
					name="role_evaluator3" id="role_evaluator3"></select></div>
				</td>
			</tr>
			<tr>
				<td>
				<div class="left"><toastmaster:label styleClass="desc"
					key="agenda.grammarian" /> <select class="medium"
					name="role_grammarian" id="role_grammarian"></select></div>
				</td>
				<td>
				<div><toastmaster:label styleClass="desc"
					key="agenda.secretary" /> <select class="medium"
					name="role_secretary" id="role_secretary"></select></div>
				</td>
			</tr>
			<tr>
				<td>
				<div class="left"><toastmaster:label styleClass="desc"
					key="agenda.timer" /> <select class="medium" name="role_timer"
					id="role_timer"></select></div>
				</td>
				<td>
				<div><toastmaster:label styleClass="desc"
					key="agenda.ah_counter" /> <select class="medium"
					name="role_ah_counter" id="role_ah_counter"></select></div>
				</td>
			</tr>
			<tr>
				<td>
				<div class="left"><toastmaster:label styleClass="desc"
					key="agenda.vote_counter" /> <select class="medium"
					name="role_vote_counter" id="role_vote_counter"></select></div>
				</td>
				<td>
				<div><toastmaster:label styleClass="desc"
					key="agenda.vedio_operator" /> <select class="medium"
					name="role_video_operator" id="role_video_operator"></select></div>
				</td>
			</tr>
			<tr>
				<td colspan="2"><toastmaster:label styleClass="desc"
					key="agenda.additionalMsg" /> <textarea name="additionalMsg"
					class="small">
                </textarea></td>
			</tr>
			<tr>
				<td colspan="2"><toastmaster:label styleClass="desc"
					key="agenda.minutes" /> <form:errors path="minutes"
					cssClass="fieldError" /> <form:textarea path="minutes"
					id="minutes" cssClass="text large" /></td>
			</tr>
		</table>
		<li class="buttonBar bottom"><c:out value="${buttons}" escapeXml="false" /></li>
	</ul>
</form:form>

<script type='text/javascript' src='/toastmaster/dwr/engine.js'></script>
<script type='text/javascript'
	src='/toastmaster/dwr/interface/UserManager.js'></script>
<script type='text/javascript'
	src='/toastmaster/dwr/interface/AgendaManager.js'></script>
<script type='text/javascript' src='/toastmaster/dwr/util.js'></script>
<script type='text/javascript'>
    
    function transferRolename(rolename) {
        if(rolename.indexOf("role_speaker")!= -1) {
            return "role_speaker";
        }
        
        if(rolename.indexOf("role_evaluator") != -1) {
            return "role_evaluator";
        }
        
        return rolename;
    }
    
    role_num=0;
    function populateUser(rolename)
    {
        var agendaDate = dwr.util.getValue("date");
        var tempRolename = transferRolename(rolename);
       
        UserManager.getOrderedUsers(tempRolename, agendaDate, {
            callback: function(users) {
                    dwr.util.removeAllOptions(rolename);
                    var id = dwr.util.getValue("id"); 
                    if (id == undefined || id == null || id == "") {
                        dwr.util.addOptions(rolename,[" "]);
                        dwr.util.addOptions(rolename, users,"username","optionString");
                    } else {
                        AgendaManager.getUserbyRole(id,rolename, {
                            callback: function(userwrapper) {
                                if (userwrapper != null) {
                                    dwr.util.addOptions(rolename, [userwrapper], "username", "optionString"); 
                                }
                                dwr.util.addOptions(rolename,[" "]);
                                dwr.util.addOptions(rolename, users,"username","optionString");
                            }
                        });
                    }
		    role_num++;
		    if (role_num == 16) {
			document.getElementById("xh").setAttribute("style", "display:");
		    }
            }
        });
    }
    
    function fillMinutesTemplete() {
        var ss = document.agendaForm.minutes.value;
        if (ss.length <= 1) {
            document.agendaForm.minutes.value = 
                "[To be completed by the Secretary after the meeting]\n\n"
                + "contents: \n"
                + "1. attendance (additional members and guests other than functionaries)\n" 
                + "2. table topics session respondents\n"
                + "3. award winners (best speaker, table topic speaker, evaluator)\n"
                + "4. club announcements and other miscellaneous.\n";
        }
    }
    fillMinutesTemplete();
    populateUser("role_president");
    populateUser("role_toastmaster");
    populateUser("role_table_topic_master");
    populateUser("role_general_evaluator");
    populateUser("role_speaker1");
    populateUser("role_evaluator1");
    populateUser("role_speaker2");
    populateUser("role_evaluator2");
    populateUser("role_speaker3");
    populateUser("role_evaluator3");
    populateUser("role_grammarian");
    populateUser("role_secretary");
    populateUser("role_ah_counter");
    populateUser("role_video_operator");
    populateUser("role_vote_counter");
    populateUser("role_timer");
    </script>

<script type="text/javascript">
    Form.focusFirstElement($('agendaForm'));
</script>

<v:javascript formName="agenda" cdata="false" dynamicJavascript="true"
	staticJavascript="false" />


